@extends('app')
@include('UEditor::head')
@section('content')
<link href="{{ asset('/css/spinners.css') }}" rel="stylesheet">
<div id="grid" class="grid" style="position: fixed;z-index: 1000;left:50%;display: none;">
    <div class="cell">
        <div class="card">
            <span class="throbber-loader">Loading…</span>
        </div>
    </div>
</div>

<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="tabbable" id="tabs-876069">
                <ul class="nav nav-tabs">
                    <li class="active">
                        <a href="#panel-656128" data-toggle="tab">问题列表</a>
                    </li>
                    <li>
                        <a href="#panel-952476" data-toggle="tab">搜索</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <!--列表开始-->
                    <div class="tab-pane active" id="panel-656128">
                        <div class="panel panel-default mt20">

                        <div class="table-responsive panel-body">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" name="checkAll" value=""></th>
                                    <th>问题标题</th>
                                    <th>所属分类</th>
                                    <th>回答</th>
                                    <th>关注</th>
                                    <th>浏览</th>
                                    <th>作者</th>
                                    <th>首页推荐</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($questions as $res)
                                <tr id="news_{{ $res->id }}">
                                    <td><input type="checkbox" name="questions" value="{{ $res->id }}"></td>
                                    <td><a href="{{ url('/bbs/'.$res->id)}} ">{{ str_limit($res->title,20) }}</a></td>
                                    <td><a href="{{ url('/bbs/board/'.$res->category_id)}} ">{{ count($res->getBbsCatByQuestion)>0?str_limit($res->getBbsCatByQuestion->title,14):'分类已删除'}}</a></td>
                                    <td>{{ $res->comment_count }}</td>
                                    <td>{{ $res->focus_count }}</td>
                                    <td>{{ $res->view_count }}</td>
                                    <td>{{getUserName($res->publish_uid)}}</td>
                                    <td id="disabled">
                                        @if($res->is_hot == 1)
                                        <span class="glyphicon glyphicon-ok-circle  green-remove"
                                            onclick="changeUserStatus('/admin/bbs/question/recomment','{{ $res->id }}', '{{ $res->is_hot }}', '{{ csrf_token() }}')"></span>
                                        @else
                                        <span class="glyphicon glyphicon-remove-circle red-ok"
                                              onclick="changeUserStatus('/admin/bbs/question/recomment','{{ $res->id }}', '{{ $res->is_hot }}', '{{ csrf_token() }}')"></span>
                                        @endif
                                    </td>
                                    <td>{{ date('Y-m-d',strtotime($res->created_at)) }}</td>
                                    <td>
                                        <a href="javascript:void(0);" onclick="del_one('/admin/bbs/questions/delete','{{$res->id}}','{{ csrf_token() }}','question_id')"><i class="glyphicon glyphicon-remove-sign"></i></a>
                                    </td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                        </div>
                        <div>
                            <a class="btn btn-danger" onclick="batch_del('/admin/bbs/questions/deletes','{{ csrf_token() }}', 'question_id', 'questions'); ">删除</a>
                        </div>
                        <div>{!! $questions->render() !!} </div>
                    </div>
                    <!--列表结束-->

                    <!--搜索开始-->
                    <div class="panel panel-default tab-pane mt20" id="panel-952476">
                        <div class="main">
                            <div style="width: 50%;float: left;">
                                <form class="form-horizontal" action="/admin/bbs/questions/index" method="get">
                                    <div class="form-group">
                                        <label for="" class="col-sm-2 control-label">关键词:</label>
                                        <div class="col-sm-10">
                                            <input type="text" name="question_title" class="form-control" id="inputEmail3" placeholder="输入关键词">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-2 control-label">分类:</label>
                                        <div class="col-sm-10">
                                            <select class="form-control" name="category_id">
                                                @foreach($bbs_cat as $bc)
                                                <option value="{{ $bc->id }}">{{ $bc->title }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="inputPassword3" style="padding-left: 1px;" class="col-sm-2 control-label">发起时间:</label>
                                        <div class="col-sm-10">
                                            <div class="input-group date form_datetime col-md-9" data-date="" data-date-format="" data-link-field="dtp_input1">
                                                <input class="form-control" size="40" type="text" name="created_at" value="" data-date-format="yyyy-mm-dd" readonly>
                                                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                                <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-2 control-label">作者:</label>
                                        <div class="col-sm-10">
                                            <input type="text" name="author" class="form-control" id="inputPassword3" placeholder="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-2 control-label">回复数:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="inputPassword3"
                                                   name="answer_users_s" style="width: 100px;float: left;">
                                            <input type="text" class="form-control" id="inputPassword3"
                                                   name="answer_users_e" style="width: 100px;float: left;margin-left: 30px;">
                                        </div>
                                    </div>
                                    {!! csrf_field() !!}
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="submit" class="btn btn-primary">搜索</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$('input').iCheck({
	checkboxClass: 'icheckbox_flat-blue',
    radioClass: 'iradio_flat-blue',
    increaseArea: '-10' // optional
});
//处理全选函数
$('input[name=checkAll]').on('ifChecked', function(event){
	$('input:checkbox').iCheck('check');
});
$('input[name=checkAll]').on('ifUnchecked', function(event){
	$('input:checkbox').iCheck('uncheck');
});
    function selectCourse(id,url,token)
    {
        $.ajax({
            'url':url,
            'type':'POST',
            'data':"id="+id+'&_token='+token,
            success: function(data){
                if(data.status == 'success'){
                    result = data.data;
                    option = '<option value="0">--无--</option>';
                    $.each(result, function(k,e){
                        option += '<option value="'+e.id+'">'+e.name+'</option>';
                    });
                    $("#course").html(option);
                }

            }
        });
    }
   $(function(){
	   $('.form_datetime').datetimepicker({
	        format:'yyyy-mm-dd',
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
	        autoclose: 1,
	        todayHighlight: 1,
	        startView: 2,
	        minView: 2,
	        forceParse: 0
	    });
        /***图片上传****/
        $("#uploadfile").uploadify({
            'formData'     : {
                'app':'bbs',
                'fileField':'upfile',
                '_token':'{{ csrf_token() }}'
            },
            "width"           : 120,
            "height"          : 30,
            "queueSizeLimit"  :1,
            "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
            "fileObjName"     : "upfile",
            "buttonText"      : "插入封面",
            "uploader"        : '/admin/upload/uploadimg',
            'removeTimeout'   : 1,
            'fileTypeExts'    : '*.jpg; *.png; *.gif;*.xlsx',
            'onSelect'        : function(){
                 $('.loading').css({'display': 'block'});
            },
          'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    
    	            var html="<div style='width:90px; height:60px;float:left;'>"
    	            	+"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
    	            	+"</div>"
    	            $('#imgbox').html(html);
//     	            bindImg();
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
			}

        });
    });
</script>
@endsection
